<?php include $this->templateDir . 'common/header.php'; ?>
<body>
<link rel="stylesheet" href="/static/layui/extend/formSelects-v4.css">
<div class="yadmin-body animated fadeIn">
    <form action="" method="post" class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label for="username" class="layui-form-label"> 昵称  </label>
            <div class="layui-input-block">
                <input type="text" id="manager_uname" name="manager_uname" value="<?php echo $this->EditInfo['manager_uname']?>" lay-verify="required" lay-vertype="tips" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="email" class="layui-form-label"> 邮箱 </label>
            <div class="layui-input-block">
                <input type="text" id="email" name="email"  value="<?php echo $this->EditInfo['email']?>" lay-verify="required|email" lay-vertype="tips" autocomplete="off" class="layui-input">
            </div>
        </div>
        <!-- 编辑时不显示密码框 -->
        <div class="layui-form-item">
            <label for="password" class="layui-form-label"> 新密码 </label>
            <div class="layui-input-block">
                <input type="password" id="password" name="password"  lay-vertype="tips" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"> 角色归属 </label>
            <div class="layui-input-block">
                <select name="manager_role_id" xm-select="role-select" lay-verify="required" lay-vertype="tips">
                    <option value="">请选择角色</option>
                    <?php
                    foreach ($this->roles as $key => $value) {
                        if($value['role_id'] == $this->EditInfo['manager_role_id']){
                            echo '<option value="'.$value['role_id'].' " selected="selected">'.$value['role_name'].'</option>';
                        }else{
                            echo '<option value="'.$value['role_id'].'">'.$value['role_name'].'</option>';
                        }
                    }
                    ?>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block" style="margin-left:0;text-align:center;">
                <input type="hidden" id="userId" name="userId" value="<?php echo $this->EditInfo['id']?>">
                <button class="layui-btn layui-btn-normal btn-w100" lay-submit="" lay-filter="edit">修改信息</button>
            </div>
        </div>
    </form>
</div>
<script src="/static/js/common.js"></script>
<script>
    layui.config({
        base: '/static/layui/extend/'
    }).extend({
        formSelects: 'formSelects-v4'
    }).use(['form', 'layer', 'formSelects'], function () {
        var  $ = layui.jquery
            ,form = layui.form
            , layer = layui.layer
            , formSelects = layui.formSelects;

        //修改功能
        form.on('submit(edit)', function (form) {
            form.field.role = formSelects.value('role-select', 'val');
            var arr = form.field.role;
            if(arr.length > 1){
                layer.msg("角色归属 只能选择一个", {icon: 7});
                return false;
            }
            var id              =  $("#userId").val();
            var manager_uname   =  $("#manager_uname").val();
            var email           =  $("#email").val();
            var password        =  $("#password").val();

            $.ajax({
                url:'<?php echo PG_SROOT?>manage/edit/'+id
                ,type:"post"
                ,dataType:"json"
                ,data:{
                    'manager_uname'  :   manager_uname
                    ,'email'          :   email
                    ,'password'       :   password
                    ,'manager_role_id':   arr[0]
                }
                , success:function (res) {
                    if(res.status == "ok"){
                        layer.msg(res.data,{icon:6},function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            window.parent.location.reload();
                        });
                    }else{
                        layer.msg(res.data,{icon:7});
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>